package com.jsy.common.util.publicApi.mybatis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ApiKeyServiceImpl implements ApiKeyService {

    @Autowired
    private ApiKeyMapper apiKeyMapper;

    @Override
    public ApiKey createApiKey(ApiKey apiKey) {
        apiKeyMapper.insert(apiKey);
        return apiKey;
    }

    @Override
    public void deleteApiKey(Long id) {
        apiKeyMapper.deleteById(id);
    }

    @Override
    public void updateApiKey(ApiKey apiKey) {
        apiKeyMapper.update(apiKey);
    }

    @Override
    public ApiKey getApiKey(Long id) {
        return apiKeyMapper.selectById(id);
    }

    @Override
    public ApiKey getApiKeyByAccessKey(String accessKey) {
        return apiKeyMapper.selectByAccessKey(accessKey);
    }

    @Override
    public List<ApiKey> getAllApiKeys() {
        return apiKeyMapper.selectAll();
    }

    @Override
    public List<ApiKey> getApiKeysByStatus(Integer status) {
        return apiKeyMapper.selectByStatus(status);
    }
}